package net.hn.hnms.biz.project.controller;


import cn.dev33.satoken.annotation.SaCheckPermission;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import net.hn.hnms.biz.project.domain.ContractInvoice;
import net.hn.hnms.biz.project.domain.ContractPayment;
import net.hn.hnms.biz.project.request.ContractInfoReq;
import net.hn.hnms.biz.project.request.ContractInvoiceReq;
import net.hn.hnms.biz.project.service.ContractInvoiceService;
import net.hn.hnms.biz.project.vo.ContractInfoVo;
import net.hn.hnms.biz.project.vo.ContractInvoiceVo;
import net.hn.hnms.sys.common.core.domain.R;
import net.hn.hnms.sys.common.core.domain.ResponsePage;
import net.hn.hnms.sys.common.core.web.controller.BaseController;
import net.hn.hnms.sys.common.log.annotation.Log;
import net.hn.hnms.sys.common.log.enums.BusinessType;
import net.hn.hnms.sys.common.mybatis.core.page.PageQuery;
import net.hn.hnms.sys.common.satoken.config.AutoSetMineCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(value = "发票信息", tags = {"发票信息"})
@RestController
@RequestMapping("/contract/invoice")
public class ContractInvoiceController extends BaseController{

    @Autowired
    private ContractInvoiceService contractInvoiceService;
    /**
     * 新增发票信息
     */
    @ApiOperation("新增发票信息")
    @SaCheckPermission("contract:invoice:add")
    @PostMapping("/add")
    @Log(title = "新增发票信息", businessType = BusinessType.INSERT)
    public R<Void> add(@Validated @RequestBody ContractInvoiceReq contractInvoiceReq) {
        return toAjax(contractInvoiceService.insert(contractInvoiceReq));
    }

    /**
     * 删除发票信息
     */
    @ApiOperation("删除发票信息")
    @SaCheckPermission("contract:invoice:delete")
    @ApiImplicitParam(name = "idList", value = "要删除的id值,用逗号间隔", required = true, allowMultiple = true, dataType = "String", paramType = "query")
    @PostMapping("delete")
    @Log(title = "删除发票信息", businessType = BusinessType.DELETE)
    public R<Void> delete(@RequestParam("idList") List<String> idList) {
        contractInvoiceService.updateDeleteByIds(idList);
        return R.ok();
    }

    /**
     * 更新发票信息
     */
    @ApiOperation("更新发票信息")
    @SaCheckPermission("contract:invoice:update")
    @PostMapping("/update")
    @Log(title = "更新发票信息", businessType = BusinessType.UPDATE)
    public R<Void> update(@Validated @RequestBody ContractInvoiceReq contractInvoiceReq) {
        contractInvoiceService.updateById(contractInvoiceReq);
        return R.ok();
    }

    /**
     * 发票信息详情
     */
    @ApiOperation("发票信息详情")
    @GetMapping("/{id}")
    public R<ContractInvoice> detail(@PathVariable("id") String id) {
        return R.ok(contractInvoiceService.selectDetailById(id));
    }

    /**
     * 发票信息列表
     */
    @ApiOperation("发票信息列表")
    @GetMapping("/page")
    public R<ResponsePage<ContractInvoiceVo>> page(ContractInvoiceReq contractInvoiceReq, PageQuery pageQuery) {
        return R.ok(contractInvoiceService.selectPageList(contractInvoiceReq, pageQuery));
    }

    /**
     * 合同信息列表
     */
    @ApiOperation("合同信息列表")
    @GetMapping("/getContractPage")
    @AutoSetMineCode
    public R<ResponsePage<ContractInfoVo>> getContractPage(ContractInfoReq contractInfoReq, PageQuery pageQuery) {
        return R.ok(contractInvoiceService.selectContractPageList(contractInfoReq, pageQuery));
    }

    /**
     * 结算信息列表
     */
    @ApiOperation("根据合同ID查结算信息列表")
    @GetMapping("/getPayList")
    @AutoSetMineCode
    public R<List<ContractPayment>> getPayList(ContractInvoiceReq ContractInvoiceReq) {
        return R.ok(contractInvoiceService.getPayList(ContractInvoiceReq));
    }





}
